package Start;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;

import DataBase.DB_Factory;
import RemoteServer.AdminServer;
import RemoteServer.CustomerServer;
import RemoteServer.GeneralManagerServer;
import RemoteServer.SaleManagerServer;
import RemoteServerInterface.AdminServerInterface;
import RemoteServerInterface.CustomerServerInterface;
import RemoteServerInterface.GeneralManagerServerInterface;
import RemoteServerInterface.SaleManagerServerInterface;
import View.ServerView;

public class Main {

	private static String url = null;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new Main().start();
	}
	
	private void start(){
		try {
			InputStreamReader in = new InputStreamReader(getClass().getResourceAsStream("/address.ini"));
			BufferedReader reader = new BufferedReader(in);
			url = reader.readLine();
			reader.close();
			LocateRegistry.createRegistry(8888);
			AdminServerInterface adminServer = new AdminServer();
			Naming.rebind("rmi://"+url+"/adminServer", adminServer);
			CustomerServerInterface customerServer = new CustomerServer();
			Naming.rebind("rmi://"+url+"/customerServer", customerServer);
			GeneralManagerServerInterface generalManagerServer = new GeneralManagerServer();
			Naming.rebind("rmi://"+url+"/generalManagerServer", generalManagerServer);
			SaleManagerServerInterface saleManagerServer = new SaleManagerServer();
			Naming.rebind("rmi://"+url+"/saleManagerServer",saleManagerServer);
			in = new InputStreamReader(getClass().getResourceAsStream("/address.ini"));
			DB_Factory.initDB(in);
			ServerView.getServerView().showOperation("start!");
		} catch (Exception e) {
			ServerView.getServerView().showOperation(e.toString());
		}
	}
	
}
